package com.ruoyi.web.controller.module.commonInfo;

import java.util.List;
import java.util.Arrays;

import com.ruoyi.common.utils.PageUtils;
import com.ruoyi.system.domain.module.commonInfo.CommonInfoOrder;
import com.ruoyi.system.service.module.commonInfo.ICommonInfoOrderService;
import lombok.RequiredArgsConstructor;
import javax.validation.constraints.*;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import com.ruoyi.common.annotation.RepeatSubmit;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.validate.AddGroup;
import com.ruoyi.common.core.validate.EditGroup;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

/**
 * 跳蚤、易货商品的 订单Controller
 *
 * @author ruoyi
 * @date 2022-12-13
 */
@Validated
@Api(value = "跳蚤、易货商品的 订单控制器", tags = {"跳蚤、易货商品的 订单管理"})
@RequiredArgsConstructor(onConstructor_ = @Autowired)
@RestController
@RequestMapping("/module/commonInfo/order")
public class CommonInfoOrderController extends BaseController {

    private final ICommonInfoOrderService commonInfoOrderService;

    /**
     * 查询跳蚤、易货商品的 订单列表
     */
    @ApiOperation("查询跳蚤、易货商品的 订单列表")
    @PreAuthorize("@ss.hasPermi('module:commonInfoOrder:list')")
    @GetMapping("/list")
    public TableDataInfo<CommonInfoOrder> list(@Validated CommonInfoOrder commonInfoOrder) {
        QueryWrapper<CommonInfoOrder> qw = new QueryWrapper<>();

        TableDataInfo<CommonInfoOrder> td = PageUtils.buildDataInfo(commonInfoOrderService.page(PageUtils.buildPage(),qw));
        List<CommonInfoOrder> list = td.getRows();
        return td;
    }

    /**
     * 导出跳蚤、易货商品的 订单列表
     */
    @ApiOperation("导出跳蚤、易货商品的 订单列表")
    @PreAuthorize("@ss.hasPermi('module:commonInfoOrder:export')")
    @Log(title = "跳蚤、易货商品的 订单", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult<CommonInfoOrder> export(@Validated CommonInfoOrder commonInfoOrder) {
        List<CommonInfoOrder> list = commonInfoOrderService.list();
        ExcelUtil<CommonInfoOrder> util = new ExcelUtil<CommonInfoOrder>(CommonInfoOrder.class);
        return util.exportExcel(list, "跳蚤、易货商品的 订单");
    }

    /**
     * 获取跳蚤、易货商品的 订单详细信息
     */
    @ApiOperation("获取跳蚤、易货商品的 订单详细信息")
    @PreAuthorize("@ss.hasPermi('module:commonInfoOrder:query')")
    @GetMapping("/{id}")
    public AjaxResult<CommonInfoOrder> getInfo(@NotNull(message = "主键不能为空") @PathVariable("id") Long id) {
        CommonInfoOrder commonInfoOrder = commonInfoOrderService.getById(id);
        return AjaxResult.success(commonInfoOrder);
    }

    /**
     * 新增跳蚤、易货商品的 订单
     */
    @ApiOperation("新增跳蚤、易货商品的 订单")
    @PreAuthorize("@ss.hasPermi('module:commonInfoOrder:add')")
    @Log(title = "跳蚤、易货商品的 订单", businessType = BusinessType.INSERT)
    @RepeatSubmit
    @PostMapping()
    public AjaxResult<Void> add(@Validated(AddGroup.class) @RequestBody CommonInfoOrder commonInfoOrder) {
        return toAjax(commonInfoOrderService.save(commonInfoOrder) ? 1 : 0);
    }

    /**
     * 修改跳蚤、易货商品的 订单
     */
    @ApiOperation("修改跳蚤、易货商品的 订单")
    @PreAuthorize("@ss.hasPermi('module:commonInfoOrder:edit')")
    @Log(title = "跳蚤、易货商品的 订单", businessType = BusinessType.UPDATE)
    @RepeatSubmit
    @PutMapping()
    public AjaxResult<Void> edit(@Validated(EditGroup.class) @RequestBody CommonInfoOrder commonInfoOrder) {
        return toAjax(commonInfoOrderService.updateById(commonInfoOrder) ? 1 : 0);
    }

    /**
     * 删除跳蚤、易货商品的 订单
     */
    @ApiOperation("删除跳蚤、易货商品的 订单")
    @PreAuthorize("@ss.hasPermi('module:commonInfoOrder:remove')")
    @Log(title = "跳蚤、易货商品的 订单" , businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult<Void> remove(@NotEmpty(message = "主键不能为空")  @PathVariable Long[] ids) {
        return toAjax(commonInfoOrderService.removeByIds(Arrays.asList(ids)) ? 1 : 0);
    }
}
